<?php

    session_start();

    //print_r($_SERVER);die;
    //$this_page = basename($_SERVER['SCRIPT_NAME'],'.php');
    //echo $this_page;die;

    if (empty($_COOKIE['auto_login'])) {

        if(empty($_SESSION['admin']) && $a != 'login' && $a != 'code' && $a != 'sign-up'){

            echo '<script type="text/javascript">alert("请先登录！");self.location.href="index.php?c=admin&a=login&admin=1";</script>';die;

        }
    }
    if(!empty($_COOKIE['auto_login']) && !empty($_SESSION) && $a == 'login'){
        header('location:index.php');

    }

    if(!empty($_COOKIE['auto_login']) && empty($_SESSION)){

        $_SESSION['admin']['username'] = $_COOKIE['username'];
        $_SESSION['admin']['password'] = $_COOKIE['password'];
        if ($this_page == 'login') {
            header('location:index.php');
        }else{
            header('location:index.php?c='.$c.'&a='.$a.'&admin=1');
        }

    }


    include_once('my_db.php');
    $link = db_connect('test');


?>